//存储层核心代码

/**
 * localStorange
 */

 const STRINGTYPE = "string"

 /**
  * 保存localStorage
  */

export const setStorage = (key,data)=>{
  if(!key){
    return;
  }
  if(typeof(data)!= STRINGTYPE){
    data=JSON.stringify(data);
  }
  localStorage.setItem(key,data);
}

/**
 * 读取localStorane
 */

export const getStorage = (key)=>{
  if(!key){
    return;
  }
  return JSON.parse(localStorage.getItem(key));
}

/**
 * 删除localStorage
 */

export const removeStorage = (key)=>{
  if(!key){
    return;
  }
  localStorage.removeItem(key)
} 

/**
 * 清空localStorage
 */

export const clearStorage = ()=>{
  localStorage.clear()
}




